Do not process forwarded commands until node is part of the network#7936
Conversation
|
@copilot add the C++ unit test, and add a check_one_of() to the StateMachine so we can pass a std::set and avoid calling the atomic multiple times when we check if we are in one of the set of states. |
Done in the latest commit:
|
|
@copilot please add this unit test as well:
|
Added in
It also covers |
|
@copilot the formatting, please. |
The failing check was "Release notes": |
There was a problem hiding this comment.
Pull request overview
This PR tightens node-to-node message handling by ensuring forwarded commands are only dispatched once the node is in a “part of network” startup state, aligning forwarded command gating with existing channel/consensus message gating.
Changes:
- Introduces
recv_node_inbound_messagehelper to parse and dispatchnode_inboundmessages behind the startup-state guard. - Adds
StateMachine::check_one_of()plus new unit tests covering the new helper and state-machine API. - Updates release metadata (CHANGELOG + Python package version) for a 7.0.6 patch release.
Custom instructions used:
.github/copilot-instructions.md.github/instructions/reviewing.instructions.md.github/instructions/changelog.instructions.md
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/node/node_inbound_message.h |
Adds shared dispatch helper to gate forwarded/channel/consensus node messages behind startup-state checks. |
src/node/node_state.h |
Routes recv_node_inbound through the new helper. |
src/ds/state_machine.h |
Adds check_one_of() helper for checking membership in multiple allowed states. |
src/ds/test/state_machine.cpp |
Adds unit coverage for StateMachine basics and check_one_of(). |
src/node/test/node_inbound_message.cpp |
Adds unit coverage ensuring inbound messages (including forwarded) are dropped/processed based on startup state. |
CMakeLists.txt |
Registers the two new unit test executables. |
CHANGELOG.md |
Adds a 7.0.6 “Fixed” entry referencing #7936. |
python/pyproject.toml |
Bumps Python package version to 7.0.6 to match the CHANGELOG. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: achamayou <[email protected]>
Co-authored-by: achamayou <[email protected]>
Forwarded commands received in
recv_node_inbound(src/node/node_state.h) were dispatched tocmd_forwarder->recv_message(...)unconditionally, bypassing the "part of network" state guard applied to all other node-to-node messages. A node could therefore execute a forwarded command while still in an early startup state, with potentially undefined behaviour for some commands.Changes
src/node/node_inbound_message.h: New header-only helperrecv_node_inbound_message, which reads a serialisednode_inboundmessage and gates dispatch behind the "part of network" state check, so forwarded commands are gated identically to channel and consensus messages — processed only inpartOfNetwork,partOfPublicNetwork, orreadingPrivateLedger. Messages arriving too early are dropped with the sameLOG_DEBUG_FMTas other node messages. The guard uses the newStateMachine::check_one_of()helper.src/node/node_state.h:recv_node_inboundnow delegates to the newrecv_node_inbound_messagehelper. The previously-unreachableLOG_FAIL_FMTin theforwarded_msgcase is replaced by the real handler; dispatch logic is otherwise unchanged.src/ds/state_machine.h: Addedcheck_one_of(const std::set<T>&), which loads the atomic state once and checks membership against the provided set of states, avoiding repeated atomic reads when checking whether the node is in one of several states.src/ds/test/state_machine.cpp/src/node/test/node_inbound_message.cpp/CMakeLists.txt: Added two C++ unit tests (state_machine_testandnode_inbound_message_test).CHANGELOG.md/python/pyproject.toml: Added a new## [7.0.6]/Fixedentry (with its release-tag link) and bumped the Python package version to7.0.6to match, so the "Release notes" CI check (which requires the first CHANGELOG version to matchpyproject.toml) passes. The entry references this PR,#7936.Testing
state_machine_test(src/ds/test/state_machine.cpp): exercises theStateMachineAPI and the newcheck_one_ofhelper, including empty-set and state-transition edge cases.node_inbound_message_test(src/node/test/node_inbound_message.cpp): drivesrecv_node_inbound_messagewith a serialisednode_inboundmessage and stub forwarder/channel/consensus handlers. Asserts that in early states (uninitialized,initialized,pending,readingPublicLedger) aforwarded_msgis not dispatched, and that inpartOfNetwork,partOfPublicNetwork, andreadingPrivateLedgerit is dispatched with the expectedfrom/payload. Also coverschannel_msgandconsensus_msgbeing gated identically.